package com.example.demo.controller.excel;

import com.example.demo.entity.CollectionName;
import com.example.demo.entity.Result;
import com.example.demo.service.excel.ExcelService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @description:
 * @author: cj
 * @create: 16-03-08 16:06:01
 */
@RequestMapping("excel")
@RestController
public class ExcelController {
    @Resource
    ExcelService excelService;

    /**
     * excel 导入
     *
     * @param file 文件
     * @return 成功或者失败
     */
    @PostMapping("/incFile")
    public Result incFile(@RequestParam("file") MultipartFile file) {
        Boolean aBoolean = excelService.inc( file, CollectionName.ESSAY );
        if (aBoolean) {
            return Result.ok( "添加成功" );
        } else {
            return Result.error( "操作失败" );
        }

    }
}
